import Vue from 'vue'
import Router from 'vue-router'
import IndexLayout from '@/views/index'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/500',
    component: () => import('@/views/500'),
    hidden: true
  },

  {
    path: '/',
    component: IndexLayout,
    children: [{
      path: '/',
      component: () => import('@/views/home')
    },
    {
      path: 'about',
      component: () => import('@/views/about')
    },
    {
      path: 'home',
      component: () => import('@/views/home')
    },
    {
      path: 'search',
      component: () => import('@/views/home')
    },
    {
      path: 'info',
      component: () => import('@/views/blog/Info')
    },
    {
      path: 'create',
      component: () => import('@/views/blog/Create')
    },
    {
      path: 'center',
      component: () => import('@/views/center')
    },
    {
      path: '/profile',
      component: () => import('@/views/profile/index'),
      hidden: true
    },
    {
      path: '*',
      component: () => import('@/views/404')
    }]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
